
import { IColumn, IField } from 'well-log-vis/entity/field';
import { testTable } from './test-table';
import { DataType, IndicatorTypes, TrackType, utils } from 'well-log-vis';
import { IWellLogTrackIndicator } from 'well-log-vis/entity/indicator';
import { ITable } from 'well-log-vis/model/interfaces';
import { IWellLogTrack } from 'well-log-vis/entity/track';

export const data = utils.createWellLogDraft('井随钻工程路径图');
data.tracks = {};

function createFieldDraft(column: IColumn, name?: string, extras?: any): IField {
  if (column['unit']) {
    name = name || `${column.name}(${column['unit']})`;
  } else {
    name = name || column.name;
  }
  const field = utils.createFieldDraft(column, name);
  if (extras) {
    Object.keys(extras).forEach(key => {
      field[key] = extras[key];
    })
  }
  return field;
}
function findColumn(table: ITable, columnName: string): IColumn {
  return table.columns.find(col => col.columnName === columnName) as IColumn;
}

let indicator: IWellLogTrackIndicator, track: IWellLogTrack;
const depthColumn = findColumn(testTable, 'p2');
const depthField = createFieldDraft(depthColumn, undefined, {
  format: {[depthColumn.dataType]: { format: 'mm:ss' } },
});
const trackHeight = 60;
// -----------------------------------------------------------
track = utils.createTrackDraft('Track 1', 0);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 大钩高度
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p7').name, 0);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p7'))];
track.indicators[indicator.id] = indicator;
// 大钩负荷
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p12').name, 1);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p12'))];
track.indicators[indicator.id] = indicator;
// 钻压
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p13').name, 2);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p13'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
// axis track
const axisTrack = utils.createTrackDraft('时间轴', 1);
axisTrack.style.height = trackHeight;
axisTrack.indicators = {};
// 时间
indicator = utils.createIndicatorDraft(IndicatorTypes.TIMEAXIS, findColumn(testTable, 'p7').name, 0);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [
  createFieldDraft(findColumn(testTable, 'p5')),
  createFieldDraft(findColumn(testTable, 'p97')),
  createFieldDraft(findColumn(testTable, 'p6')),
];
axisTrack.indicators[indicator.id] = indicator;
data.tracks[axisTrack.id] = axisTrack;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 2', 2);
track.style.width = 50;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 转盘转速
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p14').name, 0);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p14'))];
track.indicators[indicator.id] = indicator;
// 扭矩
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p15').name, 1);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p15'))];
track.indicators[indicator.id] = indicator;
// 平均钻时
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p10').name, 2);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p10'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 3', 3);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 1#泵冲
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p19').name, 1);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p19'), '1#泵冲')];
track.indicators[indicator.id] = indicator;
// 2#泵冲
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p20').name, 2);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p20'), '2#泵冲')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 3#泵冲
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p21').name, 3);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p21'), '3#泵冲')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 4', 4);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 立管压力
// indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p19').name, 1);
// indicator.tableId = testTable.id;
// indicator.tableName = testTable.name;
// indicator.depthField = depthField;
// indicator.fields = [createFieldDraft(findColumn(testTable, 'p19'))];
// track.indicators[indicator.id] = indicator;
// 套管压力
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p18').name, 2);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p18'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 5', 5);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 1#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p30').name, 1);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p30'), '1#池体积')];
track.indicators[indicator.id] = indicator;
// 2#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p31').name, 2);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p31'), '2#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 3#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p32').name, 3);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p32'), '3#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 4#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p33').name, 4);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p33'), '4#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 5#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p34').name, 5);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p34'), '5#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 6', 6);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 6#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p35').name, 6);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p35'), '6#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 7#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p73').name, 7);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p73'), '7#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 8#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p74').name, 8);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p74'), '8#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 9#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p75').name, 9);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p75'), '9#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 10#池体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p76').name, 10);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p76'), '10#池体积')];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 7', 7);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 总体积
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p37').name, 0);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p37'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 8', 8);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 入口温度
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p26').name, 6);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p26'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 出口温度
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p27').name, 7);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p27'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 入口密度
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p24').name, 8);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p24'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 出口密度
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p25').name, 9);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p25'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 9', 9);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 入口电导
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p28').name, 6);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p28'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 出口电导
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p29').name, 7);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p29'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 入口流量
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p22').name, 8);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p22'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// 出口流量
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p23').name, 9);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p23'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 10', 10);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// 总烃
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p39').name, 6);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p39'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// c1
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p40').name, 7);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p40'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// c2
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p41').name, 8);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p41'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// c3
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p42').name, 9);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p42'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 11', 11);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// iC4
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p43').name, 6);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p43'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// nC4
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p44').name, 7);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p44'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// iC5
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p45').name, 8);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p45'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// nC5
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p46').name, 9);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p46'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================

// -----------------------------------------------------------
track = utils.createTrackDraft('Track 12', 12);
track.style.width = 40;
track.style.height = trackHeight;
track.style.type = TrackType.STACKING;
track.indicators = {};
// CO2
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p48').name, 6);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p48'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// H2
indicator = utils.createIndicatorDraft(IndicatorTypes.LINE, findColumn(testTable, 'p47').name, 7);
indicator.tableId = testTable.id;
indicator.tableName = testTable.name;
indicator.depthField = depthField;
indicator.fields = [createFieldDraft(findColumn(testTable, 'p47'))];
track.indicators[indicator.id] = indicator;
data.tracks[track.id] = track;
// ===========================================================
data.id = 'w01';
export const welllog = data;